import observe from "./observe";

var obj = {
  a: {
    m: {
      n: 5
    }
  },
  b: 10,
  c: {
    d: {
      e: {
        f: 6666
      }
    }
  },
  g: [22, 33, 44, 55]
};

observe(obj);
// obj.a = { hh: 123 };
// obj.g = [123]
// obj.g.push(123);
// obj.z += 10
obj.a = 10;
obj.g.push(123)
console.log(obj);



// 数组判断
let arr = [1, 2, 3];
// let res = Object.prototype.toString.call(arr).slice(8, -1);
let res = Array.isArray(arr)
console.log(res);



// proxy
let onWatch = (obj, setBind, getLogger) => {
  let handler = {
    get(target, property, receiver) {
      getLogger(target, property)
      return Reflect.get(target, property, receiver)
    },
    set(target, property, value, receiver) {
      setBind(value, property)
      return Reflect.set(target, property, value)
    }
  }
  return new Proxy(obj, handler)
}
let obj1 = { a: 1 }
let p = onWatch(
  obj1,
  (v, property) => {
    console.log(`监听到属性${property}改变为${v}`)
  },
  (target, property) => {
    console.log(`'${property}' = ${target[property]}`)
  }
)
p.a = 2 // 监听到属性a改变
p.a // 'a' = 2


let exampleObj = {
  a: 1,
  b: 2
}

let keys = Object.keys(exampleObj);
console.log(keys);